package FuntionTest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.function.Function;

public class test2 {
    //需求：
    //获取学生姓名放到数组
    public static void main(String[] args) {
        ArrayList<Student> list=new ArrayList<>();
        list.add(new Student("zhangsan",18) );
        list.add(new Student("lisi",18) );
        list.add(new Student("wangwu",20) );

        String[] array = list.stream().map(new Function<Student, String>() {
            @Override
            public String apply(Student student) {
                return student.getName();
            }
        }).toArray(String[]::new);

//        String[] array = list.stream().map(Student::getName).toArray(String[]::new);
        System.out.println(Arrays.toString(array));

    }
}
